#include "knowledges.h"

namespace IAlib
{

Knowledges::Knowledges()
{
    m_type = UnknownKnowledge;
    m_last_check = 0;
}

QList<Fact*> Knowledges::getAssociatedFacts() const
{
    return m_associated_facts;
}

void Knowledges::addAssociatedFact(const Fact& fact)
{
    bool exist = false;
    for (int i = 0; i < m_associated_facts.size(); i++)
    {
        if (m_associated_facts[i]->getFactName() == fact.getFactName())
        {
            exist = true;
            break;
        }
    }
    if (!exist)
    {
        Fact* newFact = new Fact(fact);
        m_associated_facts.append(newFact);
    }
    else
    {
        Fact * newFact = getAssociatedFact(fact.getFactName());
        newFact->setFactStat(fact.getFactStat());
    }
}

void Knowledges::addAssociatedFacts(const QList<Fact>& list_fact)
{
    for (int i = 0; i < list_fact.size(); i++)
    {
        addAssociatedFact(list_fact[i]);
    }
}

bool Knowledges::removeAssociatedFact(const QString& fact_name)
{
    for (int i = 0; i < m_associated_facts.size(); i++)
    {
        if (m_associated_facts[i]->getFactName() == fact_name)
        {
            m_associated_facts.removeAt(i);
            return true;
        }
    }
    return false;
}

Fact* Knowledges::getAssociatedFact(const QString& fact_name)
{
    for (int i = 0; i < m_associated_facts.size(); i++)
    {
        if (m_associated_facts[i]->getFactName() == fact_name)
        {
            return m_associated_facts[i];
        }
    }
    return NULL;
}

}
